﻿using System;
using System.Linq;
using ECommon.Components;
using Infrastructure;

namespace QueryServices.Ef
{
    [Component]
    public class ReplyQueryService : BaseQueryService, IReplyQueryService
    {
        public dynamic FindDynamic(string id, string option)
        {
            if (option == "simple")
            {
                using (Repository.EntityFramework.Forums.DataContext db = new Repository.EntityFramework.Forums.DataContext())
                {
                    var q = db.Reply.AsNoTracking().AsQueryable();
                    var reply = q.Where(x => x.Id == id)
                        .Select(x => new
                    {
                        id = x.Id,
                        body = x.Body,
                        postId = x.PostId,
                        parentId = x.ParentId,
                        authorId = x.AuthorId,
                        createdOn = x.CreatedOn
                    }).SingleOrDefault();
                    return reply;
                }
            }
            throw new Exception("Invalid find option:" + option);
        }
    }
}
